/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package nl.windesheim.archdemo.dao;

import nl.windesheim.archdemo.model.Address;
import java.util.List;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

/**
 *
 * @author re0053273
 */
@Transactional
public class AddressDao {
    @Autowired
    private SessionFactory sessionFactory;

    public void setSessionFactory(SessionFactory sessionFactory) {
        this.sessionFactory = sessionFactory;
    }

    public List<Address> getAll() {
        return this.sessionFactory.getCurrentSession()
                .createQuery("from Address address").list();
    }

    public Address save(Address o){
        this.sessionFactory.getCurrentSession().saveOrUpdate(o);
        return o;
    }
}
